<template>
	<view>
		<u-swiper @change="change" :list="lun" :height="250" :effect3d="true" :interval="3000" @click="click(idd)">
		</u-swiper>
		<uni-group title="活动分类">
			<view class="item-container">
				<view class="thumb-box" v-for="(item1, index1) in fen" :key="index1" @click="dianji(item1.link)">
					<view class="item-menu-name">{{item1.name}}</view>
				</view>
			</view>
		</uni-group>
		<uni-group title="活动列表">
			<uni-card :title="item.title" v-for="(item,index) in list" @click="click(item.id)">
				<image :src="base+item.imgUrl" mode="" style="width: 100%;"></image>
				<view>报名人数：{{item.signupNum}}</view>
				<view>点赞数：{{item.likeNum}}</view>
				<view>发布时间：{{item.publishTime}}</view>
				<br>
				<button type="warn" @click.stop="ba(item.id)">报名</button>
			</uni-card>
		</uni-group>
	</view>

</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				base: api.baseurl,
				lun: [],
				fen: [],
				idd: '',
				list: []
			}
		},
		onLoad() {
			this.getlun()
			this.getlun2()
			this.getlun3()
		},
		methods: {
			ba(id) {
				this.$post(this.base + '/prod-api/api/activity/signup', {
					"activityId": id
				}).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '报名成功'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			getlun() {
				this.$get(this.base + '/prod-api/api/activity/rotation/list').then((res) => {
					res.rows.forEach((item) => {
						this.lun.push({
							image: this.base + item.advImg,
							id: item.targetId
						})
					})
				})
			},
			getlun3() {
				this.$get(this.base + '/prod-api/api/activity/activity/list').then((res) => {
					this.list = this.arr(res.rows)
				})
			},
			arr(arr) {
				for (var i = 0; i < arr.length - 1; i++) {
					for (var j = 0; j < arr.length - 1; j++) {
						if (new Date(arr[j].publishTime) < new Date(arr[j + 1].publishTime)) {
							var str = arr[j]
							arr[j] = arr[j + 1]
							arr[j + 1] = str
						}
					}
				}
				return arr
			},
			getlun2() {
				this.$get(this.base + '/prod-api/api/activity/category/list').then((res) => {
					this.fen = res.data
				})
			},
			change(e) {
				this.idd = this.lun[e].id
				console.log(e)
			},
			click(id) {
				if(id == null | id == ''){
					uni.showToast({
						title:'id为空',
						icon:'none'
					})
					return
				}
				uni.navigateTo({
					url: 'xianq?id=' + id
				})
			}
		}
	}
</script>

<style>
	.item-container {
		display: flex;
		flex-wrap: wrap;
	}

	.thumb-box {
		width: 33.333333%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.item-menu-image {
		width: 120rpx;
		height: 120rpx;
	}
</style>
